// 图标添加文本方法
const CreateLabel = (marker, color, name) => {
    let label = new BMapGL.Label(name, {
        offset: new BMapGL.Size(-20, 35),
    });
    label.setStyle({
        color: color,
        fontSize: 12 + 'px',
        fontFamily: "黑体",
        fontWeight:600,
        // textShadow: '-1px 1px 0 #fff',Microsoft YaHei
        border: '',
        backgroundColor: 'transparent',
    });
    marker.setLabel(label);
    return;
};

const CreateLabel2 = (marker, color, name) => {
    let label = new BMapGL.Label(name, {
        offset: new BMapGL.Size(-15, 20),
    });
    label.setStyle({
        color: color,
        fontSize: 10 + 'px',
        fontFamily: "黑体",
        // textShadow: '-1px 1px 0 #fff',Microsoft YaHei
        border: '',
        backgroundColor: 'transparent',
    });
    marker.setLabel(label);
    return;
};

// 2.创建地图图标的方法
const CreateMark = (iconUrl, width, height, lng, lat, clas, id, name, rotation, color) => {
    // 注意require不能再这里包裹参数iconUrl，需要再外面将路径包裹好
    var icon = new BMapGL.Icon(iconUrl, new BMapGL.Size(width, height));
    var point = new BMapGL.Point(lng, lat);
    // 创建图标
    var marker = new BMapGL.Marker(point, {
        icon: icon,
    });
    marker.id = id;
    // 为图标加属性予以区别车(包括车状态)，医院，场馆
    if (clas == 'taskvehicle') {
        marker.clas = 'taskvehicle';
        CreateLabel(marker, 'red', name);
        marker.setRotation(rotation);
    }
    else if (clas == 'onvehicle') {
        marker.clas = 'onvehicle';
        CreateLabel(marker, 'blue', name);
        marker.setRotation(rotation);
    }
    else if (clas == 'notaskvehicle') {
        marker.clas = 'notaskvehicle';
        CreateLabel(marker, 'gray', name);
        marker.setRotation(rotation);
    }
    else if (clas == 'hospital') {
        marker.clas = 'hospital';
    }
    else if (clas == 'venue') {
        marker.clas = 'venue';
    }
    else if (clas == 'venue-medical-point-online') {
        marker.clas = 'venue-medical-point-online';
        CreateLabel2(marker, color, name);
    }
    else if (clas == 'venue-medical-point-offline') {
        marker.clas = 'venue-medical-point-offline';
        CreateLabel2(marker, color, name);
    }
    else if (clas == 'notguarantee-task-vehicle') {
        marker.clas = 'notguarantee-task-vehicle';
        CreateLabel(marker, 'red', name);
        marker.setRotation(rotation);
    }
    else if (clas == 'notguarantee-ontask-vehicle') {
        marker.clas = 'notguarantee-ontask-vehicle';
        CreateLabel(marker, 'green', name);
        marker.setRotation(rotation);
    }
    return marker
};

export { CreateMark, CreateLabel }